#!/bin/bash

echo "正在启动Ubuntu桌面环境..."
echo

# 检查Docker是否运行
if ! docker info > /dev/null 2>&1; then
    echo "错误: Docker未运行，请先启动Docker服务"
    exit 1
fi

# 检查docker-compose是否安装
if ! command -v docker-compose &> /dev/null; then
    echo "错误: docker-compose未安装，请先安装docker-compose"
    exit 1
fi

echo "构建Docker镜像..."
docker-compose build

if [ $? -ne 0 ]; then
    echo "构建失败，请检查错误信息"
    exit 1
fi

echo "启动容器..."
docker-compose up -d

if [ $? -ne 0 ]; then
    echo "启动失败，请检查错误信息"
    exit 1
fi

echo
echo "Ubuntu桌面环境已启动！"
echo
echo "访问方式:"
echo "1. 本地显示: 确保X11服务器运行，然后运行: docker exec -it ubuntu-desktop-xfce startxfce4"
echo "2. VNC访问: 使用VNC客户端连接到 localhost:5900"
echo "3. SSH访问: ssh -p 2222 ubuntu@localhost"
echo
echo "查看容器状态: docker-compose ps"
echo "查看日志: docker-compose logs -f"
echo "停止服务: docker-compose down"
echo 